package sanshui.system.trade.factory.notify.channelImpl;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.stereotype.Component;
import sanshui.system.trade.common.GlobalContain;
import sanshui.system.trade.factory.notify.AbstractTradeSysNotify;
import sanshui.system.trade.factory.notify.TradeSysNotify;
import sanshui.system.trade.factory.notify.TradeSysNotifyModel;

@Component
@Slf4j
public class QiYeWxNotifyImpl extends AbstractTradeSysNotify {
    @Override
    public String getNotifyChannel() {
        return GlobalContain.NotifyChannel.QiYe_Wx.name();
    }

    @Override
    public boolean execute(TradeSysNotifyModel notifyModel) {
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId("your_corp_id");
        config.setAgentId(1000001);
        config.setCorpSecret("your_corp_secret");

        // 创建 WxCpService 实例
        WxCpService wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);

        // 创建文本消息
        WxCpMessage message = WxCpMessage.TEXT().toUser("user_id")
                .content("这是一条测试消息").build();

        try {
            // 发送消息
            wxCpService.getMessageService().send(message);
            System.out.println("消息发送成功");
        } catch (Exception e) {
            log.info("企业微信发送失败", e);
        }
        return false;
    }
}
